<template>
  <div>
    <!-- 租赁合同信息 -->
    <div class="card-wrap flex-column justify-end card-padding">
      <el-form :model="form" ref="leaseContract" label-width="100px">
        <div class="card-title-wrap">
          <span>租赁合同信息</span>
          <span></span>
        </div>
        <!-- 租赁合同信息 -->
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="主订单编码:">
              <span style="color: #1890ff; cursor: pointer" @click="orderDetail">{{ form.mainOrderCode | filterNull }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="子订单编码:">
              <span>{{ form.orderCarCode | filterNull }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合同时间:">
              <span>{{ form.contractStartTime | filterNull }} 至 {{ form.contractEndTime | filterNull }} </span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="标准日租金:">
              <span>{{ format_thousand(form.dailyRent) }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合同保证金:">
              <span>{{ format_thousand(form.deposit) }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户名称:">
              <span>{{ form.customerName | filterNull }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="form.oldCarNo">
            <el-form-item label="车牌号:">
              <span>{{ form.oldCarNo | filterNull }}</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  name: 'leaseContract',
  props: {
    value: {
      type: Object,
      default: {},
    },
    state: {
      type: String,
      default: '',
    },
  },
  computed: {
    form: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      },
    },
    type() {
      let status
      switch (this.state) {
        case 'write':
          status = 'edit'
          break
        case 'disabled':
          status = 'detail'
          break
        case 'readonly':
          status = 'detail'
          break
        case 'detail':
          status = 'detail'
          break
        case 'edit':
          status = 'edit'
        case 'add':
          status = 'add'
          break
      }
      return status
    },
  },
  data() {
    return {}
  },
  created() {},
  methods: {
    // 订单详情
    orderDetail() {
      this._toPage({
        path: '/vehicleOrder/orderManagement/OrderDetails',
        name: 'OrderDetails',
        query: {
          type: this.form.carType,
          orderId: this.form.orderId,
          calcSchemeId: this.form.calcSchemeId,
        },
      })
    },
    valid() {
      return new Promise(async (resolve) => {
        let result = true
        let refs = Object.values(this.$refs)
        for (let index = 0; index < refs?.length; index++) {
          const ref = refs[index]
          if (Object.prototype.toString.call(ref) == '[object Array]') {
            for (let i = 0; i < ref.length; i++) {
              const element = ref[i]
              if (element?.valid) {
                let rc = await element?.valid?.()
                result = result && rc
              }
              if (element?.validate) {
                let rf = await this._valid(ref)
                result = result && rf
              }
              if (element?.form_validate) {
                let rf = await this._valid(ref, 'form_validate')
                result = result && rf
              }
            }
          } else {
            if (ref?.valid) {
              let rc = await ref?.valid?.()
              result = result && rc
            }
            if (ref?.validate) {
              let rf = await this._valid(ref)
              result = result && rf
            }
            if (ref?.form_validate) {
              let rf = await this._valid(ref, 'form_validate')
              result = result && rf
            }
          }
        }
        resolve(result)
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.box-wraps:after {
  content: '';
  display: block;
  clear: both;
  width: 32%;
}
</style>
